<template lang="html">
  <div  v-loading="loading2">
      <div class="bt">
        <el-button type="primary" @click="back">返回上一级</el-button>
        <el-button v-if="!this.$route.query.id" type="primary" @click="confirm('post')" :disabled="disableda">发布</el-button>
        <el-button v-else type="primary" @click="confirm('put')" :disabled="disableda">更新</el-button>

      </div>
      <div class="ww">
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
              <el-form-item label="质检流程名称" prop="name">
                  <el-input v-model="ruleForm.procedureName"></el-input>
              </el-form-item>
              <el-form-item label="质检流程描述" prop="name">
                  <el-input v-model="ruleForm.procedureDesc"></el-input>
              </el-form-item>
            </el-form>
            <div class="quill">
              <!-- <quill-editor
                  v-model="ruleForm.detailContent"
                  ref="myQuillEditor">
              </quill-editor> -->
              <EditorVue v-model="article.content"/>
            </div>
      </div>
  </div>
</template>

<script>

import {
  addflow,
  flowDetails
} from "@/api/shoppingCentre/shoppingCentre";
  import EditorVue from '@/components/Editor.vue'
export default {
  components : {
    EditorVue,
  },
  data () {
    return {
      ruleForm : {
          procedureName : '',
          procedureDesc : '',
          detailContent :'',
      },
      article : {
        content :''
      },
      loading2 : false,
      disableda : false,
      rules : {

      }
    }
  },
  mounted () {
      if (this.$route.query.id) {
        this.loading2 = true;
          flowDetails(this.$route.query.id).then(res=>{
            if (res.data.code =='OK') {
              this.ruleForm.procedureName = res.data.data.procedureName;
              this.ruleForm.procedureDesc = res.data.data.procedureDesc;
              this.article.content = res.data.data.procedureDetail;
              this.loading2 = false
            } else {
              this.$message.error(res.data.message);
            }
          })
      }
  },
  methods : {
    back () {
      this.$router.push({
        name : 'qualityFlow'
      })
    },
    confirm (method) {
      this.disableda = true;
      var data = {
        procedureName : this.ruleForm.procedureName,
        procedureDesc : this.ruleForm.procedureDesc,
        procedureDetail : this.article.content,
        procedureId : this.$route.query.id
      }
      addflow(data,method).then(res=>{
         if (res.data.code == 'OK') {
            this.$message.success('发布成功');
            setTimeout(()=>{
              this.$router.push({
                name : 'qualityFlow'
              })
            },1000)
         } else {
           this.$message.error(res.data.message);
             this.disableda = false;
         }
      })
    }
  }
}
</script>

<style scoped>
  .bt {
    margin-top: 20px;
  }
  .ww {
    background: #ffff;
    padding: 33px;
    margin-top: 20px;
  }
  .el-form {
    width: 349px;

  }
</style>
